package cn.gene.timeyan.article.webapi.controller;


import cn.gene.timeyan.article.service.TopService;
import cn.gene.timeyan.article.webapi.service.impl.TopServiceImpl1;
import cn.gene.timeyan.common.restful.JsonResult;
import cn.gene.timeyan.pojo.article.vo.SimpleArticleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 缃?《琛 前端控制器
 * </p>
 *
 * @author LWG
 * @since 2022-07-25
 */
@RestController
@RequestMapping("/top")
@Api(tags = "top模块")
public class TopController {
    @Autowired
    private TopService topService;

    @Autowired
    TopServiceImpl1 topServiceImpl1;

    @GetMapping("/{modelId}/list")
    @ApiOperation("/置顶文章列表")
    public JsonResult<List<SimpleArticleVO>> list(@PathVariable("modelId") Long modelId){
        List<SimpleArticleVO> list=topService.getTopList(modelId);
        return JsonResult.ok(list);
    }

    @RequestMapping("/newTop")
    @ApiOperation("生成置顶帖子")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户id",name="userId",example = "1"),
            @ApiImplicitParam(value = "帖子的id",name="articleId",example = "1"),
            @ApiImplicitParam(value = "开始时间",name="startTime",example = "2016-06-19"),
            @ApiImplicitParam(value = "结束时间",name="endTime",example = "2022-06-19")
    })
    public JsonResult<Void> addNewTop(Long userId, Long articleId,
                                      @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime,
                                      @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime){
        System.out.println("<--------------------开始处理新增置顶--------------------->");
        topServiceImpl1.addNewTopService(userId,articleId,startTime,endTime);
        return JsonResult.ok();


    }
}

